package com.jpcc.vw.onlineRadio.utils;


import com.jpcc.vw.onlineRadio.R;
import com.jpcc.vw.onlineRadio.application.MusicApplication;
import com.jpcc.vw.onlineRadio.constants.Constants;
import com.jpcc.vw.onlineRadio.model.bean.BaseBean;
import com.jpcc.vw.onlineRadio.service.AlbumRadioAudioPlayer;
import com.orhanobut.logger.Logger;

import rx.Subscriber;

/**
 * 共同的地方处理Rxjava
 * Created by liukanshan on 2017/1/1.
 */

public abstract class CommonSubscriber<T extends BaseBean> extends Subscriber<T> {

    public abstract void onSuccess(T response);

    public abstract void onFailure(BaseBean response);

    @Override
    public void onError(Throwable e) {
        Logger.i("onError-->"+e.toString());
        BaseBean error=new BaseBean();
        error.setCode(-1);
        error.setStatusMessage(MusicApplication.GetInstance().getResources().getString(R.string.string_88));
        onFailure(error);
    }

    @Override
    public void onNext(T t) {
        if (Constants.STATUS_SUCCESS_CODE==t.getCode()) {
            onSuccess(t);
        } else {
            if(t.getCode()==Constants.ERROR_CODE_NOT_BIND||t.getCode()==Constants.ERROR_CODE_NOT_BIND2){
                t.setStatusMessage(MusicApplication.GetInstance().getResources().getString(R.string.string_107));
            }
            onFailure(t);
        }
    }

    @Override
    public void onCompleted() {

    }
}
